Index


RISC World

Easy C++ Manual

Copyright © ProAction and APDL, 2001

Input/output <stdio.h>

The header <stdio.h> declares three types, several macros, and many functions performing input and output.

The type size_t is the unsigned integral type of the result of the sizeof operator.

The type FILE is an object type capable of recording all the information needed to control a stream, including its file position indicator, a pointer to its associated buffer (if any), an error indicator that records whether a read/write error has occurred, and an end-of file indicator that records whether the end of the file has been reached.

The type fpos_t is an object type capable of recording all the information needed to specify uniquely every position within a file.

The macro NULL expands to an implementation-defined null pointer constant.

The macros _IOFBF, _IOLBF and _IONBF expand to integral constant expressions with distinct values, suitable for use as the third argument to the setvbuf function.

The macro BUFSIZ expands to an integral constant expression, which is the size of the buffer used by the setbuf function.

The macro EOF expands to a negative constant expression that is returned by several functions to indicate end-of-file, that is, no more input from a stream.

The macro FOPEN_MAX expands to an integral constant expression that is the minimum number of files that the implementation guarantees can be open simultaneously.

The macro FILENAME_MAX expands to an integral constant expression that is the size needed for an array of char large enough to hold the longest file name string that the implementation guarantees can be opened.

The macro L_tmpnam expands to an integral constant expression that is the size needed for an array of char large enough to hold a temporary file name string generated by the tmpnam function.

The macros SEEK_CUR, SEEK_END and SEEK_SET expand to distinct integral constant expressions with distinct values, suitable for use as the third argument to the fseek function.

The macro TMP_MAX expands to a integral constant expression that is the minimum number of unique file names that shall be generated by the tmpnam function.

stderr, stdin and stdout are expressions of type "pointer to FILE" that point to the FILE objects associated, respectively, with the standard error, input and output streams.

Operations on files

  Name  remove

  Syntax  int remove(const char *filename);

  Description  Cause the file whose name is the string pointed to by filename to be no longer accessible by that name. A subsequent attempt to remove that file using that name will fail, unless it is created anew. If the file is open, the remove function is implementation-defined.

  Returns  Zero if the operation succeeds, nonzero if it fails.

  Name  rename  

  Syntax  int rename (const char *old, const char *new);

  Description  Cause the file whose name is the string pointed to by old to be henceforth known by the name given by the string pointed to by new. The file named old is no longer accessible by that name. If the file named new already exists, the rename function will fail.

  Returns  Zero if the operation succeeds, nonzero if it fails, in which case if the file existed previously it is still known by its original name.

  Name  tmpfile

  Syntax  FILE *tmpfile(void);

  Description  Create a temporary binary file that will automatically be removed when it is closed or at program termination. If the program terminates abnormally, whether an open temporary file is removed is implementation-defined. The file is opened for update with "wb+" mode.

  Returns  A pointer to the stream of the file that it created. If the file cannot be created, the tmpfile function returns a null pointer.

  Name  tmpnam

  Syntax  char *tmpnam(char *s);

  Description  Generate a string that is a valid filename and that is not the same as the name of an existing file. The tmpnam function generates a different string each time it is called, up to TMP_MAX times. If it is called more than TMP_MAX times, the behaviour is implementation-defined. The implementation shall behave as if no library function calls the tmpname function.

  Returns  If the argument is a null pointer, the tmpnam function leaves its result in an internal static object and returns a pointer to that object. Subsequent call to the tmpnam function may modify the same object. If the argument is not a null pointer, it is assumed to point to an array of at least L_tmpnam chars; the tmpnam function writes its result in that array and returns the argument as its value.

File access functions

  Name  fclose

  Syntax  int fclose(FILE *stream);

  Description  Cause the stream pointed to by stream to be flushed and the associated file to be closed. Any unwritten buffered data for the stream are delivered to the host environment to be written to the file; any unread buffered data are discarded. The stream is disassociated from the file. If the associated buffer was automatically allocated, it is deallocated.

  Returns  Zero if the stream was successfully closed, or EOF if any errors were detected.

  Name  fflush

  Syntax  int fflush(FILE *stream);

  Description  If stream points to an output or an update stream in which the most recent operation was not input, the fflush function causes any unwritten data for that stream to be delivered to the host environment to be written to the file; otherwise, the behaviour is undefined. If stream is a null pointer, the fflush function performs the flushing action on all streams for which the behaviour is defined above.

  Returns  EOF if a write error occurs otherwise, zero.

  Name  fopen

  Syntax  FILE *fopen(const char *filename, const char *mode);

  Description  Open the file whose name is the string pointed to by filename, and associate a stream with it. The argument mode points to a string beginning with one of the following sequences:

r   open text file for reading w   truncate to zero length or create text file for writing a   append; open or create text file for writing at EOF rb   open binary file for reading wb   truncate to zero length or create binary file for writing ab   append; open or create binary file for writing at EOF r+   open text file for update (reading and writing) w+   truncate to zero length or create text file for update a+   append; open or create text file for update, writing at EOF r+b or rb+  open binary file for update (reading and writing) w+b or wb+  truncate to zero length or create binary file for update a+b or ab+  append; open or create bin file for update, writing at EOF

Opening a file with read mode ('r' as the first character in the mode argument) fails if the file does not exist or cannot be read.

Opening a file with append mode ('a' as the first character in the mode argument) causes all subsequent writes to the file to be forced to the then current end-of-file, regardless of intervening calls to the fseek function.

When a file is opened with update mode ('+') as the second or third character in the above list of mode argument values), both input and output may be performed on the associated stream. However, output may not be directly followed by input without an intervening call to the fflush function or to a file positioning function (fseek, fsetpos, or rewind), and input may not be directly followed by output without an intervening call to a file positioning function, unless the input operation encounters end-of-file.

  Returns  A pointer to the object controlling the stream. If the open operation fails, fopen returns a null pointer.

  Name  freopen

  Syntax  FILE *freopen(const char *filename, const char *mode, FILE *stream);

  Description  Open the file whose name is the string pointed to by filename and associates the stream pointed to by stream with it. The mode argument is used just as in the fopen function. The freopen function first attempts to close any file that is associated with the specified stream. Failure to close the file successfully is ignored. The error and end-of-file indicators for the stream are cleared.

  Returns  A null pointer if the open operation fails. Otherwise freopen returns the value of stream.

  Name  setbuf

  Syntax  void setbuf(FILE *stream, char *buf);

  Description  Except that it returns no value, setbuf is equivalent to the setvbuf function invoked with the value _IOFBF for mode and BUFSIZ for size, or (if buf is a null pointer), with the value _IONBF for mode.

  Returns  Void

  Name  setvbuf

  Syntax  int setvbuf(FILE *stream, char *buf, int mode, size_t size);

  Description  May be used after the stream pointed to by stream has been associated with an open file and before any other operation is performed on the stream. The argument mode determines how stream will be buffered, as follows: _IOFBF causes input/output to be fully buffered; _IOLBF causes input/output to be line buffered; _IONBF causes input/output to be unbuffered. If buf is not a null pointer, the array it points to may be used instead of a buffer allocated by the setvbuf function. The argument size specifies the size of the array. The contents of the array at any time are indeterminate.

  Returns  Zero on success, or nonzero if an invalid value is given for mode or if the request cannot be honoured.

Formatted input/output functions

  Name  fprintf

   Syntax  int fprintf(FILE *stream, const char *format, ...);

  Description  Write output to the stream pointed to by stream, under control of the string pointed to by format that specifies how subsequent arguments are converted for output. If there are insufficient arguments for the format, the behaviour is undefined. If the format is exhausted while arguments remain, the excess arguments are evaluated (as always) but are otherwise ignored. The fprintf function returns when the end of the format string is encountered.

    The format is composed of zero or more directives: ordinary multibyte characters (not %), which are copied unchanged to the output stream; and conversion specifications, each of which results in fetching zero or more subsequent arguments. Each conversion specification is introduced by the character %. After the %, the following appear in sequence:

�  Zero or more flags that modify the conversion specification:

-  The result of the conversion will be left-justified within the field.

+  The result of a signed conversion will always begin with a plus or minus sign.

space  If the first character of a signed conversion is not a sign, or if a signed conversion results in no characters, a space will be prefixed to the result.

#  The result is to be converted to an "alternate form". For o conversion, it increases the precision to force the first digit of the result to be a zero. For x (or X) conversion, a nonzero result will have 0x (or 0X) prefixed to it. For e, E, f, g, and G conversions, the result will always contain a decimal-point character, even if no digits follow it. For g and G conversions, trailing zeros will not be removed from the result.

0  For d, i, o, u, x, X, e, E, f, g, and G conversions, leading zeros are used to pad to the field width; no space padding is performed. If the 0 and - flags both appear, the 0 flag will be ignored. For d, i, o, u, x, and X conversions, if a precision is specified, the 0 flag will be ignored.

�  An optional minimum field width. If the converted value has fewer characters than the field width, it will be padded with spaces (by default) on the left (or right, if the left adjustment flag, described later, has been given) to the field width.

�  An optional precision that gives the minimum number of digits to appear for the d, i, o, u, x and X conversions, the number of digits to appear after the decimal-point character for e, E, and f conversions, the maximum number of significant digits for the g and G conversions, or the maximum number of characters to be written from a string in s conversion. The precision takes the form of a period (.) followed either by an asterisk or a decimal integer.

�  An optional h specifying that a following d, i, o, u, x, or X conversion specifier applies to a short int or unsigned short int argument; an optional h specifying that a following n conversion specifier applies to a pointer to a short int argument; an optional l specifying that a following d, i, o, u, x, or X conversion specifier applies to a long int or unsigned long int argument; an optional l specifying that a following n conversion specifier applies to a pointer to a long int argument; or an optional L specifying that the following e, E, f, g, or G conversion specifier applies to a long double argument.

�  A character that specifies the type of conversion to be applied.

A field width, or precision, or both may be indicated by an asterisk. In this case, an int argument supplies the field width or precision. The arguments specifying field width, or precision, or both, shall appear (in that order) before the argument (if any) to be converted.

The conversion specifiers and their meanings are:

d,i  The int argument is converted to signed decimal in the style [-]dddd.

o,u,x,X  The unsigned int argument is converted to octal (o), unsigned decimal (u), or unsigned hexadecimal notation (x or X) in the style dddd; the letters abcdef are used for x conversion and the letters ABCDEF for X conversion.

f  The double argument is converted to decimal notation in the style [-]ddd.ddd, where the number of digits after the decimal-point is equal to the precision. If the precision is missing, it is taken as 6; if the precision is zero and the # flag is not specified, no decimal-point character appears.

e,E  The double argument is converted in the style [-]d.ddde�dd , where there is one digit before the decimal-point character (which is nonzero if the argument is nonzero) and the number of digits after it is equal to the precision. If the precision is missing, it is taken as 6; if the precision is zero and the # flag is not specified, no decimal-point character appears.

g,G  The double argument is converted in style f or e (or in style E in the case of a G conversion specifier), with the precision specifying the number of significant digits. If the precision is zero, it is taken as 1. The style used depends on the value converted; style e (or E) will be used only if the exponent resulting from such a conversion is less than -4 or greater than or equal to the precision. Trailing zeros are removed from the fractional portion of the result; a decimal-point character appears only if it is followed by a digit.

c  The int argument is converted to an unsigned char, and the resulting character is written.

s  The argument shall be a pointer to an array of character type. Characters from the array are written up to (but not including) a terminating null character; if the precision is specified, no more than that many characters are written.

p  The argument shall be a pointer to void. The value of the pointer is converted to a sequence of printable characters, in an implementation-defined manner.

n  The argument shall be a pointer to an integer into which is written the number of characters written to the output stream so far by this call to fprintf. No argument is converted.

%  A % is written. No argument is converted.

  Returns   The number of characters transmitted, or a negative value if an output error occurred.

  Name  fscanf

  Syntax  int fscanf(FILE *stream, const char *format, ...);

  Description  Read input from the stream pointed to by stream, under control of the string pointed to by format that specifies the admissible input sequences and how they are to be converted for assignment, using subsequent arguments as pointers to the objects to receive the converted input. If there are insufficient arguments for the format the behaviour is undefined. If the format is exhausted while arguments remain, the excess arguments are evaluated (as always) but are otherwise ignored.

    The format shall be a multibyte character sequence, beginning and ending in its initial shift state. the format is composed of of zero or more directives: one or more white-space characters; an ordinary multibyte character (neither % nor a white-space character); or a conversion specification. Each conversion specification is introduced by the character %. After the %, the following appear in sequence:

�  An optional assignment-suppressing character *.

�  An optional nonzero decimal integer that specifies the maximum field width.

�  An optional h, l (ell) or L indicating the size of the receiving object. The conversion specifiers d, i, and n shall be preceded by h if the corresponding argument is a pointer to short int rather than a pointer to int, or by l if it is a pointer to long int. Similarly, the conversion specifiers o, u, and x shall be preceded by h if the corresponding argument is a pointer to unsigned short int rather than a pointer to unsigned int, or by l if it is a pointer to unsigned long int. Finally, the conversion specifiers e, f, and g shall be preceded by l if the corresponding argument is a pointer to double rather than a pointer to float, or by L if it is a pointer to long double.

�  A character that specifies the type of conversion to be applied.

The following conversion specifiers are valid:

d  Matches an optionally signed decimal integer. The corresponding argument shall be a pointer to integer.

i  Matches an optionally signed integer. The corresponding argument shall be a pointer to integer.

o  Matches an optionally signed octal integer. The corresponding argument shall be a pointer to unsigned integer.

u  Matches an optionally signed decimal integer. The corresponding argument shall be a pointer to unsigned integer.

x  Matches an optionally signed hexadecimal integer. The corresponding argument shall be a pointer unsigned integer.

e,f,g  Matches an optionally signed floating-point number. The corresponding argument shall be a pointer to floating.

s  Matches a sequence of non-white-space characters. The corresponding argument shall be a pointer to the initial character on an array large enough to accept the sequence and a terminating null character, which will be added automatically.

[  Matches a nonempty sequence of characters from a set of expected characters (the scanset). The corresponding argument shall be a pointer to the initial character of an array large enough to accept the sequence and a terminating null character, which will be added automatically. the conversion specifier includes all subsequent characters in the format string, up to and including the matching right bracket (]). The characters between the brackets (the scanlist) comprise the scanset, unless the character after the left bracket is a circumflex (^), in which case the scanset contains all characters that do not appear in the scanlist between the circumflex and the right bracket. If the conversion specifier begins with [] or [^], the right bracket character is in the scanlist.

c  Matches a sequence of characters of the number specified by the field width (1 if no field width is present in the directive). The corresponding argument shall be a pointer to the initial character of an array large enough to accept the sequence. No null character is added.

p  Matches an implementation-defined set of sequences, which should be the same as the set of sequences that may be produced by the %p conversion of the fprintf function. The corresponding argument shall be a pointer to a pointer to void.

n  No input is consumed. The corresponding argument shall be a pointer to integer into which is to be written the number of characters red from the input stream so far by this call to the fscanf function. Execution of a %n directive does not increment the assignment count returned at the completion of execution of the fscanf function.

%  Matches a single %; no conversion or assignment occurs. The complete conversion specification shall be %%.

  Returns  The value of the macro EOF if an input failure occurs before any conversion. Otherwise, the fscanf function returns the number of input items assigned, which can be fewer than provided for, or even zero, in the event of an early matching failure.

  Name  printf

  Syntax  int printf(const char *format, ...);

  Description  Equivalent to fprintf with the argument stdout interposed before the arguments to printf.

  Returns  The number of characters transmitted, or a negative value if an output error occurred.

  Name  scanf

  Syntax  int scanf(const char *format, ...);

  Description  Equivalent to fscanf with the argument stdin interposed before the arguments to scanf.

  Returns  The value of the macro EOF if an input failure occurs before any conversion. Otherwise, the scanf function returns the number of input items assigned, which can be fewer than provided for, or even zero, in the event of an early matching failure.

  Name  sprintf

  Syntax  int sprintf(char *s, const char *format, ...);

  Description  Equivalent to fprintf, except that the argument s specifies an array into which the generated output is to be written, rather than to a stream. A null character is written at the end of the characters written; it is not counted as part of the returned sum.

  Returns  Return the number of characters written in the array, not counting the terminating null character.

  Name  sscanf

  Syntax  int sscanf(const char *s, const char *format, ...);

  Description  Equivalent to fscanf, except that the argument s specifies a string from which the input is obtained, rather than from a stream. Reaching the end of the string is equivalent to encountering end-of-file for the fscanf function.

  Returns  The value of the macro EOF if an input failure occurs before any conversion. Otherwise, the sscanf function returns the number of input items assigned, which can be fewer than provided for, or even zero, in the event of an early matching failure.

  Name  vfprintf

  Syntax  int vfprintf(FILE *stream, const char *format, va_list arg);

  Description  Equivalent to fprintf, with the variable argument list replaced by arg, which shall have been initialised by the va_start macro (and possibly subsequent va_arg calls). The vfprintf function does not invoke the va_end function.

  Returns  The number of characters transmitted, or a negative value if an output error occurred.

  Name  vprintf

  Syntax  int vprintf(const char *format, va_list arg);

  Description  Equivalent to printf, with the variable argument list replaced by arg, which shall have been initialised by the va_start macro (and possible subsequent va_arg calls). The vprintf function does not invoke the va_end function.

  Returns  The number of characters transmitted, or a negative value if an output error occurred.

  Name  vsprintf

  Syntax  int vsprintf(char *s, const char *format, va_list arg);

  Description  Equivalent to sprintf, with the variable argument list replaced by arg, which shall have been initialised by the va_start macro (and possibly subsequent va_arg calls). The vsprintf function does not invoke the va_end function.

  Returns  The number of characters written in the array, not counting the terminating null character.

Character input/output functions

  Name  fgetc

  Syntax  int fgetc(FILE *stream);

  Description  Obtain the next character (if present) as an unsigned char converted to an int, from the input stream pointed to by stream, and advances the file position indicator for the stream (if defined).

  Returns  The next character from the input stream pointed to by stream. If the stream is at end-of-file, the end-of-file indicator is set and fgetc returns EOF. If a read error occurs, the error indicator is set and it returns EOF.

  Name  fgets

  Syntax  char *fgets(char *s, int n, FILE *stream);

  Description  Read at the most one less than the number of characters specified by n from the stream pointed to by stream into the array pointed to by s. No additional characters are read after a new-line character (which is retained) or after an end-of-file. A null character is written immediately after the last character read into the array.

  Returns  If successful then it returns s. If end-of-file is encountered and no characters have been read into the array, the contents of the array remain unchanged and a null pointer is returned. If a read error occurs during the operation, the array contents are indeterminate and a null pointer is returned.

  Name  fputc

  Syntax  int fputc(int c, FILE *stream);

  Description  Write the character specified by c (converted to an unsigned char) to the output stream pointed to by stream, at the position indicated by the associated file position indicator for the stream (if defined), and advances the indicator appropriately. If the file cannot support positioning requests, or if the stream was opened with append mode, the character is appended to the output stream.

  Returns  The character written. If a write error occurs, the error indicator is set and fputc returns EOF.

  Name  fputs

  Syntax  int fputs(const char *s, FILE *stream);

  Description  Write the string pointed to by s to the stream pointed to by stream. The terminating null character is not written.

  Returns  EOF if a write error occurs; otherwise it returns a non-negative value.

  Name  getc

  Syntax  int getc(FILE *stream);

  Description  Is equivalent to fgetc, except that if it is implemented as a macro, it may evaluate stream more than once, so the argument should never be an expression with side effects.

  Returns  The next character from the input stream pointed to by stream. If the stream is at end-of-file, the end-of-file indicator is set and getc returns EOF. If a read error occurs, the error indicator is set and it returns EOF.

  Name  getchar

  Syntax  int getchar(void);

  Description  Is equivalent to getc with the argument stdin.

  Returns  The next character from the input stream pointed to by stdin. If the stream is at end-of-file, the end-of-file indicator for the stream is set and getchar returns EOF. If a read error occurs, the error indicator is set and getchar returns EOF.

  Name  gets

  Syntax  char *gets(char *s);

  Description  Read characters from the input stream pointed to by stdin, into the array pointed to by s, until end-of-file is encountered or a new-line character is read. Any new-line character is discarded, and a null character is written immediately after the last character read into the array.

  Returns  If it is successful it returns s. If end-of-file is encountered and no characters have been read into the array, the contents of the array remain unchanged and a null pointer is returned. If a read error occurs during the operation, the array contents are indeterminate and a null pointer is returned.

  Name  putc

  Syntax  int putc(int c, FILE *stream);

  Description  Is equivalent to fputc, except that if it is implemented as a macro, it may evaluate stream more than once, so the argument should never be an expression with side effects.

  Returns  The character written. If a write error occurs, the error indicator for the stream is set and putc returns EOF.

  Name  putchar

  Syntax  int putchar(int c);

  Description  Is equivalent to putc with the second argument stdout.

  Returns  The character written. If a write error occurs, the error indicator for the stream is set and putchar returns EOF.

  Name  puts

  Syntax  int puts(const char *s);

  Description  Write the string pointed to by s to the stream pointed to by stdout, and appends a new-line character to the output. The terminating null character is not written.

  Returns  EOF if a write error occurs; otherwise it returns a non-negative value.

  Name  ungetc

  Syntax  int ungetc(int c, FILE *stream);

  Description  Push the character specified by c (converted to an unsigned char) back onto the input stream pointed to by stream. The pushed-back characters will be returned by subsequent reads on that stream in the reverse order of their pushing. A successful intervening call (with the stream pointed to by stream) to a file positioning function (fseek, fsetpos, or rewind) discards any pushed-back characters for the stream. The external storage corresponding to the stream is unchanged.

    One character of pushback is guaranteed. If the ungetc function is called too many times on the same stream without an intervening read or file positioning operation on that stream, the operation may fail.

    If the value of c equals that of the macro EOF, the operation fails and the input stream is unchanged.

    A successful call to the ungetc function clears the end-of-file indicator for the stream. The value of the file position indicator for the stream after reading or discarding all pushed-back characters shall be the same as it was before the characters were pushed back. For a text stream, the value of the file position indicator after a successful call to the ungetc function is unspecified until all the pushed-back characters are read or discarded. For a binary stream, its file position indicator is decremented by each successful call to the ungetc function; if it's value was zero before a call, it is indeterminate after the call.

  Returns  The character pushed back after conversion, or EOF if the operation fails.

Direct input/output functions

  Name  fread

  Syntax  size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);

  Description  Read into an array pointed to by ptr, up to nmemb members whose size is specified by size, from the stream pointed to by stream. The file position indicator for the stream (if defined) is advanced by the number of characters successfully read. If an error occurs, the resulting value of the file position indicator for the stream is indeterminate. If a partial member is read it's value is indeterminate.

  Returns  The number of members successfully read, which maybe less than nmemb if a read error or end-of-file is encountered. If size or nmemb is zero, fread returns zero and the contents of the array and the state of the stream remain unchanged.

  Name  fwrite

  Syntax  size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);

  Description  Write from the array pointed to by ptr, up to nmemb members whose size is specified by size, to the stream pointed to by stream. The file position indicator for the stream (if defined) is advanced by the number of characters successfully written. If an error occurs, the resulting value of the file position indicator for the stream is indeterminate.

  Returns  The number of members successfully written, which will be less than nmemb only if a write error is encountered.

File positioning functions

  Name  fgetpos

  Syntax  int fgetpos(FILE *stream, fpos_t *pos);

  Description  Store the current value of the file position indicator for the stream pointed to by stream in the object pointed to by pos. The value stored contains unspecified information usable by the fsetpos function for repositioning the stream to it's position at the time of the call to the fgetpos function.

  Returns  If successful, the fgetpos function returns zero; on failure, the fgetpos function returns nonzero and stores an implementation-defined positive value in errno.

  Name  fseek

  Syntax  int fseek(FILE *stream, long int offset, int whence);

  Description  Set the file position indicator for the stream pointed to by stream.

    For a binary stream the new position, measured in characters from the beginning of the file, is obtained by adding offset to the position specified by whence. The specified position is the beginning of the file if whence is SEEK_SET, the current value of the file position indicator is SEEK_CUR, or end-of-file if SEEK_END. A binary stream need not meaningfully support fseek calls with a whence value of SEEK_END.

    For a text stream, either offset shall be zero, or offset shall be a value returned by an earlier call to the ftell function on the same stream and whence shall be SEEK_SET.

    A successful call to the fseek function clears the end-of-file indicator for the stream and undoes any effects of the ungetc function on the same stream. After an fseek call, the next operation on an update stream may be either input or output.

  Returns  Nonzero only for a request that cannot be satisfied.

  Name  fsetpos

  Syntax  int fsetpos(FILE *stream, const fpos_t *pos);

  Description  Set the file position indicator for the stream pointed to by stream according to the value of the object pointed to by pos, which shall be a value obtained from an earlier call to the fgetpos function on the same stream.

    A successful call to the fsetpos function clears the end-of-file indicator for the stream and undoes any effects of the ungetc function on the same stream. After an fsetpos call, the next operation on an update stream may be either input or output.

  Returns  If successful the fsetpos function returns zero; on failure, the fsetpos function returns nonzero and stores an implementation-defined positive value in errno.

  Name  ftell

  Syntax  long int ftell(FILE *stream);

  Description  Obtain the current value of the file position indicator for the stream pointed to by stream. For a binary stream, the value is the number of characters from the beginning of the file. For a text stream, its file position indicator contains unspecified information usable by the fseek function for returning the file position indicator for the stream to its position at the time of the ftell call; the difference between two such return values is not necessarily a meaningful measure of the number of characters written or read.

  Returns  If successful the ftell function returns the current value of the file position indicator for the stream. On failure, the ftell function returns -1L and stores an implementation-defined positive value in errno.

  Name  rewind

  Syntax  void rewind(FILE *stream);

  Description  Set the file position indicator for the stream pointed to by stream to the beginning of the file.

  Returns  Void.

Error handling functions

  Name  clearerr

  Syntax  void clearerr(FILE *stream);

  Description  Clear the end-of-file and error indicators for the stream pointed to by stream.

  Returns  Void.

  Name  feof

  Syntax  int feof(FILE *stream);

  Description  Test the end-of-file indicator for the stream pointed to by stream.

  Returns  A non-zero value if and only if the end-of-file indicator is set for stream.

  Name  ferror

  Syntax  int ferror(FILE *stream);

  Description  Test the error indicator for the stream pointed to by stream.

  Returns  Non-zero if and only if the error indicator is set for stream.

  Name  perror

  Syntax  void perror(const char *s);

  Description  Map the error number in the integer expression errno to an error message. It writes a sequence of characters to the standard error stream thus : first (if s is not a null pointer and the character pointed to by s is not the null character), the string pointed to by s followed by a colon (:) and a space; then an appropriate error message string followed by a new-line character. The contents of the error message strings are the same as those returned by the strerror function with argument errno, which are implementation defined.

  Returns  Void.

APDL and ProAction

 Index